package com.example.demo.web.Controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.async.DeferredResult;

import com.example.demo.web.services.RightService;

@Controller
public class RightController {
	private RightService rightService;
    @Autowired
    public void setRightService(RightService rightService){
        this.rightService = rightService;
    }
    
    @RequestMapping(value="/righttree",method=RequestMethod.GET,produces="text/html;charset=UTF-8;") 
	public @ResponseBody String rightTree(HttpSession session) throws IOException{

		System.out.println("---------------------->>>>righttree");
		return rightService.InitTree();
		
	}
    
    @RequestMapping(value="/rightreject_tree",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody String rightreject_tree(@RequestBody String objnode, HttpSession session) throws IOException{
   		return rightService.RejectTree(objnode);
   		
   	}
    
    @RequestMapping(value="/rightreject_save",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> rightreject_save(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{	
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
   		rightService._RejectSave(deferredResult,objnode,request, session);	
   		return deferredResult;
   	}
    
    @RequestMapping(value="/right_edit",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> right_Edit(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{	 
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
   		rightService._editRight(deferredResult,objnode,request, session);	
   		return deferredResult;
   	}
    
    @RequestMapping(value="/getRightAuthList",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody String getRightAuthList(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{	    	
   		return rightService.getRightAuthList(objnode,session);		
   	}
    
    @RequestMapping(value="/rightAuthCancel",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> rightAuthCancel(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{	 
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
   		rightService._rightAuthCancel(deferredResult,objnode,request,session);	
   		return deferredResult;
   	}
    
    @RequestMapping(value="/rightAuthAdd",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> rightAuthAdd(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{	 
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
   		rightService._rightAuthAdd(deferredResult,objnode,request,session);
   		return deferredResult;
   	}
    
    @RequestMapping(value="/rightAuthEdit",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> rightAuthEdit(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{	 
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
   		rightService._rightAuthEdit(deferredResult,objnode,request,session);		
   		return deferredResult;
   	}
    
    @RequestMapping(value="/optcheck",method=RequestMethod.POST,produces="text/html;charset=UTF-8;") 
   	public @ResponseBody DeferredResult<String> optcheck(@RequestBody String objnode, HttpServletRequest request, HttpSession session) throws IOException{	  
    	DeferredResult<String> deferredResult = new DeferredResult<String>();
   		rightService._optcheck(deferredResult,objnode,request,session);	
   		return deferredResult;
   	}
	
}
